import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, token) {
      state.token = token
      // 存入cookie
      setToken(token)
    }

  },
  actions: {
    async fetchLogin(ctx, data) {
      const res = await login(data)
      ctx.commit('setToken', res)
    }
  }
}
